package com.ky.tms.controller;


import com.ky.tms.entity.TmsCarType;
import com.ky.tms.exception.PredictableException;
import com.ky.tms.service.ITmsCarTypeService;
import com.ky.tms.util.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chengkaimao
 * @since 2020-06-05
 */
@RestController
@RequestMapping("/tms/tms-car-type")
public class TmsCarTypeController {

    @Autowired
    private ITmsCarTypeService tmsCarTypeService;

    @ApiOperation("车辆类型数据分页")
    @GetMapping("page")
    public CommonResult page(TmsCarType tmsCarType, @RequestParam Long pageSize, @RequestParam Long current, HttpServletRequest request){
        return CommonResult.buildSuccess(tmsCarTypeService.page(tmsCarType, pageSize, current));
    }

    @ApiOperation("创建车辆类型")
    @PostMapping
    public CommonResult add(@RequestBody TmsCarType tmsCarType) throws PredictableException {
        tmsCarTypeService.add(tmsCarType);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("修改车辆类型")
    @PutMapping
    public CommonResult update(@RequestBody TmsCarType tmsCarType) throws PredictableException {
        tmsCarTypeService.update(tmsCarType);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("删除车辆类型")
    @DeleteMapping
    public CommonResult delete(@RequestBody List<Long> ids){
        tmsCarTypeService.delete(ids);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("搜索下拉数据")
    @GetMapping("select-list")
    public CommonResult selectList(@RequestParam Long customerId) {
        return CommonResult.buildSuccess(tmsCarTypeService.selectList(customerId));
    }

}
